<template>
  <view class="fee-table">
    <!-- 表头 -->
    <view class="fee-table_th">
      <view>费用名称</view>
      <view>费用金额</view>
      <view>费用发生时间</view>
      <view>车牌号</view>
      <view>车型</view>
    </view>
    <view class="tbody">
      <!-- 1级 -->
      <view class="tr">
        <view @click="openFlod(data)">
          <text style="margin-right: 12rpx">支出费用</text>
          <template v-if="data.feeList && data.feeList.length">
            <ve-icon v-if="data.open" name="arrow_bottom" size="28" />
            <ve-icon v-else name="arrow_top" size="28" />
          </template>
        </view>
        <!-- 正负值 -->
        <view>{{ numFormatThousands(data.amount) }}</view>
        <view>{{ data.createTime }}</view>
        <view>{{ data.carId ? data.licenseNo : '-' }}</view>
        <view>{{ data.carId ? data.carModel : '-' }}</view>
      </view>
      <!-- 2级， 3级 -->
      <view class="child-table" v-if="data.feeList && data.feeList.length > 0 && !data.open">
        <!-- 2级 -->
        <block v-for="(el, elindex) in data.feeList" :key="elindex">
          <view class="twice">
            <view>{{ el.itemName }}</view>
            <view>{{ numFormatThousands(el.amount) }}</view>
            <view>{{ el.occurTime }}</view>
            <view>{{ el.carId ? el.licenseNo : '-' }}</view>
            <view>{{ el.carId ? el.carModel : '-' }}</view>
          </view>
        </block>
      </view>
    </view>
  </view>
</template>

<script setup>
  import { ref } from 'vue'
  import { numFormatThousands } from '@/vehicle-ui/utils/tools.js'

  const props = defineProps({
    data: Object,
    mode: {
      type: String,
      default: 'detail',
    },
  })
  // 展开收起逻辑
  const openFlod = (item) => {
    item.open = !item.open //1级
    if (item.feeList) {
      item.feeList.forEach((chlid) => {
        chlid.open = false //2级
      })
    }
  }
</script>

<style lang="scss" scoped>
  .fee-table {
    margin-top: 24rpx;
    overflow-x: scroll;
    background: #f7f8fa;
    border: 1px solid #f7f8fa;

    &_th {
      height: 88rpx;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      color: #8491a8;
      font-size: 24rpx;
      view {
        flex-shrink: 0;
      }
      view:nth-child(1) {
        width: 260rpx;
        margin-left: 24rpx;
      }
      view:nth-child(2) {
        width: 160rpx;
      }
      view:nth-child(3) {
        width: 300rpx;
      }
      view:nth-child(4) {
        width: 160rpx;
      }
      view:nth-child(5) {
        width: 160rpx;
      }
      view:nth-child(6) {
        width: 270rpx;
      }
    }

    .tbody {
      padding: 12rpx 24rpx 24rpx;
      width: fit-content;
      min-width: 100%;
      background: #fff;
      .tr {
        width: 100%;
        padding: 24rpx 0 16rpx;
        background: #ffffff;
        display: flex;
        justify-content: flex-start;
        // align-items: center;
        color: #191c27;
        font-size: 28rpx;
        view {
          flex-shrink: 0;
        }
        view:nth-child(1) {
          width: 260rpx;
        }
        view:nth-child(2) {
          width: 160rpx;
        }
        view:nth-child(3) {
          width: 300rpx;
        }
        view:nth-child(4) {
          width: 160rpx;
        }
        view:nth-child(5) {
          width: 160rpx;
        }
        view:nth-child(6) {
          width: 270rpx;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
    .child-table {
      .twice {
        padding-bottom: 24rpx;
        background: #f7f8fa;
        display: flex;
        justify-content: flex-start;
        // align-items: center;
        color: #191c27;
        font-size: 28rpx;
        view:nth-child(1) {
          width: 260rpx;
          padding-left: 24rpx;
        }
        view:nth-child(2) {
          width: 160rpx;
        }
        view:nth-child(3) {
          width: 300rpx;
        }
        view:nth-child(4) {
          width: 160rpx;
        }
        view:nth-child(5) {
          width: 160rpx;
        }
        view:nth-child(6) {
          width: 250rpx;
        }

        &:first-child {
          padding-top: 24rpx;
        }
      }
      .third {
        background: #f7f8fa;
        padding-bottom: 24rpx;
        display: flex;
        justify-content: flex-start;
        // align-items: center;
        color: #191c27;
        font-size: 28rpx;
        view:nth-child(1) {
          width: 260rpx;
          padding-left: 46rpx;
        }
        view:nth-child(2) {
          width: 160rpx;
        }
        view:nth-child(3) {
          width: 250rpx;
        }
        view:nth-child(4) {
          width: 160rpx;
        }
        view:nth-child(5) {
          width: 160rpx;
        }
        view:nth-child(6) {
          width: 250rpx;
        }
      }
    }
  }
</style>
